/**
 * 20220127:created by jordia
 */
import XRConstants from "./xr-constants";

/**
 * device gamepad key mapping(corresponds to inputSource.gamepad[buttons,axes])
 */
const KEYMAP={
    /**
     * todo:
     *      confirm:on the basis of simulator,may be inconsistent with the physical
     */
    'oculus-touch':{
        [XRConstants.CONTROLLER_STYLE_COMPLEX]:{
            [XRConstants.HANDEDNESS_RIGHT]:{
                [XRConstants.GAMEPAD_BUTTON_RIGHT_TRIGGER]:{index:3, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_RIGHT_SQUEEZE]:{index:0, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_RIGHT_THUMB_STICK]:{index:1, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_GENERIC_A]:{index:4, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_GENERIC_B]:{index:5, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_RIGHT_THUMB_STICK_X]:{index:2, gesture:XRConstants.GESTURE_TYPE_PUSH},
                [XRConstants.GAMEPAD_BUTTON_RIGHT_THUMB_STICK_Y]:{index:3, gesture:XRConstants.GESTURE_TYPE_PUSH},
            },
            [XRConstants.HANDEDNESS_LEFT]:{
                [XRConstants.GAMEPAD_BUTTON_LEFT_TRIGGER]:{index:3, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_LEFT_SQUEEZE]:{index:0, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_LEFT_THUMB_STICK]:{index:1, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_GENERIC_X]:{index:4, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_GENERIC_Y]:{index:5, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_LEFT_THUMB_STICK_X]:{index:2, gesture:XRConstants.GESTURE_TYPE_PUSH},
                [XRConstants.GAMEPAD_BUTTON_LEFT_THUMB_STICK_Y]:{index:3, gesture:XRConstants.GESTURE_TYPE_PUSH},
            },
        },
    },
    'pico-neo2':{
        [XRConstants.CONTROLLER_STYLE_COMPLEX]:{
            [XRConstants.HANDEDNESS_RIGHT]:{
                [XRConstants.GAMEPAD_BUTTON_RIGHT_TRIGGER]:{index:0, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_RIGHT_SQUEEZE]:{index:1, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_RIGHT_THUMB_STICK]:{index:3, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_GENERIC_A]:{index:4, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_GENERIC_B]:{index:5, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_RIGHT_THUMB_STICK_X]:{index:2, gesture:XRConstants.GESTURE_TYPE_PUSH},
                [XRConstants.GAMEPAD_BUTTON_RIGHT_THUMB_STICK_Y]:{index:3, gesture:XRConstants.GESTURE_TYPE_PUSH},
            },
            [XRConstants.HANDEDNESS_LEFT]:{
                [XRConstants.GAMEPAD_BUTTON_LEFT_TRIGGER]:{index:0, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_LEFT_SQUEEZE]:{index:1, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_LEFT_THUMB_STICK]:{index:3, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_GENERIC_X]:{index:4, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_GENERIC_Y]:{index:5, gesture:XRConstants.GESTURE_TYPE_PRESS},
                [XRConstants.GAMEPAD_BUTTON_LEFT_THUMB_STICK_X]:{index:2, gesture:XRConstants.GESTURE_TYPE_PUSH},
                [XRConstants.GAMEPAD_BUTTON_LEFT_THUMB_STICK_Y]:{index:3, gesture:XRConstants.GESTURE_TYPE_PUSH},
            },
        },
    },
};

/**
 * get keymap by profiles
 * @param keys {[string]} profiles+handedness
 * @returns {object} device keymap
 */
const Keymap=(...keys)=>{
    let mp=KEYMAP;
    for(let i=0;i<keys.length;i++){
        let key=keys[i];
        if(!mp[key])return mp;
        mp=mp[key];
    }
    return mp;
};

export default Keymap;